package com.aurora.oa.signin.presenter;


import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.bean.HttpResult;
import com.aurora.oa.listener.OnRequestHttpDataListener;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.aurora.oa.signin.view.SigninFragmentView;
import com.aurora.oa.signin.view.SigninMainFragment;
import com.google.gson.Gson;

import java.util.Map;

/**
* Created by Administrator on 2017/03/15
*/

public class SigninFragmentPresenterImpl implements SigninFragmentPresenter{

    SigninFragmentView mView;
    RequestHttpModel mModel;

    public SigninFragmentPresenterImpl(SigninFragmentView signinMainFragment) {
        mView = signinMainFragment;
        mModel = new RequestHttpModelImpl();
    }

   public void doSignin(Map<String,String> signData){
       Map<String,String> map =signData;
       mModel.postForm(AuroraConstants.DO_SIGN_URL, map, new OnRequestHttpDataListener() {
           @Override
           public void onRequestDataSuccess(String body) {
               String result =body;
               Gson gson = new Gson();
                HttpResult resultData = gson.fromJson(body,HttpResult.class);
               if(resultData.success){
                   mView.onSigninSuccess();
               }else{
                   mView.onSigninFail(resultData.msg);
               }

           }

           @Override
           public void onRequestDataFail(String message) {
               mView.onSigninFail(message);
           }
       });
    }
}